#include "Satan.h"
#include "GameMath.h"
#include "../../data/GameInfo.h"
#include "../../data/Creator.h"

Satan::Satan()
{
    skillList = {SkillId::SKILL_RASENGAN, SkillId::SKILL_PURPLE_ENERGY,
                 SkillId::SKILL_CHIDORI, SkillId::SKILL_RASENSHURIKEN, SkillId::SKILL_WHIRL_WIND};
    GameAnimation::InitFrameData(GameInfo::Instance().texturePool[TexId::TEX_SATAN_ATTACK],
                                 animAttack, 4, 4, false, nullptr, 0.125);
    GameAnimation::InitFrameData(GameInfo::Instance().texturePool[TexId::TEX_SATAN_CHANT],
                                 animChant, 4, 2, false, [this] { isChant = false; }, 0.5);
    GameAnimation::InitFrameData(GameInfo::Instance().texturePool[TexId::TEX_SATAN_DIE],
                                 animDie, 4, 10, false, [this] { OnDie(); }, 0.05);
    GameAnimation::InitFrameData(GameInfo::Instance().texturePool[TexId::TEX_SATAN_RELEASE],
                                 animRelease, 4, 4, false, [this] { isRelease = false; }, 0.1);
    GameAnimation::InitFrameData(GameInfo::Instance().texturePool[TexId::TEX_SATAN_STANDBY],
                                 animStandBy, 4, 4);
    GameAnimation::InitFrameData(GameInfo::Instance().texturePool[TexId::TEX_SATAN_WALK],
                                 animWalk, 4, 4);
    for (int i = 0; i < Facing::SIZE; i++) {
        animRigidity[i].Copy(animDie[i]);
        animRigidity[i].timer.waitTime = 1;
        animRigidity[i].rectSrcList = {animDie[i].rectSrcList[0]};
        animRigidity[i].onFinished = [this] { OnRigidity(); };
    }

    attackMix = GameInfo::Instance().mixPool[MixId::MIX_DISCHARGE_ATTACK];
}

void Satan::OnAttack(const std::vector<std::shared_ptr<Character>> &characters)
{
    isAttack = false;
    std::shared_ptr<Skill> skill = Creator::CreateSkill(SkillId::SKILL_DISCHARGE);
    GameVector pos;
    int angle = 0;
    switch (facing) {
        case Facing::Down:
            pos = {position.x, position.y + skill->shape.w / 2};
            angle = 90;
            break;
        case Facing::Left:
            pos = {position.x - skill->shape.w / 2, position.y};
            angle = 180;
            break;
        case Facing::Right:
            pos = {position.x + skill->shape.w / 2, position.y};
            angle = 0;
            break;
        case Facing::Up:
            pos = {position.x, position.y - skill->shape.w / 2};
            angle = 270;
            break;
        default:
            break;
    }
    skill->direction = pos - position;
    skill->position = pos;
    skill->angle = angle;
    skill->id = id;
    skill->damage = damage;
    GameInfo::Instance().skills.emplace_back(skill);
}
